using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using VSSDKAssist.Assets.Actions.Base;
using VSSDKAssist.Assets.Helpers;

namespace VSSDKAssist.Recipes.Common.Actions
{
	/// <summary>
	/// Action that adds the register project factoryy call to the Initialize method
	/// </summary>
    public class AddRegisterProjectFactoryCallAction : ActionBase
	{
		#region Properties
		/// <summary>
		/// Gets or sets the project item.
		/// </summary>
		/// <value>The project item.</value>
        [Input(Required = true)]
        public CodeClass CodeClass { get; set; }

        [Input(Required = true)]
        public string CallContent { get; set; }
		#endregion

		#region Protected Implementation
		/// <summary>
		/// Called when [execute].
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
		protected override void OnExecute()
		{
            //Add/Update Initialize method
            using(AddVSPackageInitializeFunctionAction addVSPackageInitializeFunctionAction = new AddVSPackageInitializeFunctionAction())
            {
                addVSPackageInitializeFunctionAction.Site = this.Site;
                addVSPackageInitializeFunctionAction.CodeClass = this.CodeClass;
                addVSPackageInitializeFunctionAction.Execute();

                FileCodeModelHelper.InsertTextToCodeElement(
                    addVSPackageInitializeFunctionAction.CodeFunction as CodeElement, this.CallContent);
            }
		}

		/// <summary>
		/// Called when [undo].
		/// </summary>
		protected override void OnUndo()
		{
			//Do nothing
		}
		#endregion
	}
}